import React, { useState, memo } from 'react';
import { Button, message } from 'antd';

const Count = (props) => {
    const [key, setKey] = useState(0);

    const { value } = props;
    // 增加
    const handleIn = () => {
        setKey(key + 1);
    }

    // 减少
    const handleOut = () => {
        if (key < 1) {
            message.info('最小数字为0')
        } else {
            setKey(key - 1);
        }
    }

    return (
        <div>
            {console.log('----子组件渲染了----')}
            <Button type='primary' onClick={handleIn}>+</Button>
            {key}===>这是里外部传入的值：{value}
            <Button type='danger' onClick={handleOut}>-</Button>
        </div>
    )
}

export default memo(Count);

// export default ()=>{
//     return (
//         <div>11</div>
//     )
// }